
var express = require('express');
var auth = require('./auth');
var app = express();
// 替换成自己的AK和SK
var config = {
  ak: process.env.AK,
  sk: process.env.SK
}


app.use(express.json())
app.post('/', function (request, response) {
    const body = request.body;
    console.log('request body:', body);
    if (!body.headers) body.headers = {}
    body.headers['Content-MD5'] = body.content_md5
    const date = body.date;
    const req = {
      method: body.http_method,
      type: body.content_type,
      resource: body.resource,
      headers: body.headers,
      date
    }
    var signature = auth.generateAuth(config.ak, config.sk, req, null);
    response.send(signature);
});

app.listen(8000, function () {
  console.log('----- ks3 sign server started. http://localhost:8000/ -----');
});